;;;Auto invoke DDATTE, DDEDIT or DIM NEW based upon filtered selection.
;;;       Routine will only select MTEXT, TEXT, ATTRIB, DIMENSION or
;;;       INSERT w/attrib. It will report the type of entity selected
;;;       if it cannot be edited via the above commands and prompt to
;;;       select again.
;;;
;;;	It was initially intended to be a command, hence the function name
;;;       C:.... Note that the variable pstr is required, e.g. (c:ded pstr).
;;;	pstr is simply the prompt string.  It is set in redefinition
;;;	of the commands that are affected in order to give the expected
;;;	prompts.  Invoke this routine from the redefined ddedit and ddatte.
;;;
;;;	AUTHOR: Henry C. Francis
;;;		425 N. ASHE ST.
;;;		SOUTHERN PINES, NC 28387
;;;		All rights reserved without prejudice.
;;;
;;;	Copyright:	10-3-95
;;;	Edited:		11-04-2011
;;;
;;;     Added entity type "MULTILEADER"
;;;
(if (AND (>= (ATOI(SUBSTR (GETVAR "ACADVER") 1 2))15)
         (<  (ATOI(SUBSTR(GETVAR "ACADVER")1 2))17)
    )
  nil
  (progn
    (IF (< (ATOI (SUBSTR (GETVAR "ACADVER") 1 2)) 17)
      (command "undefine" "ddatte")
    )
    (defun c:ddatte (/ pstr)
      (setq pstr "\nSelect block: ")
      (if c:ded nil (load"ded"))
      (c:ded pstr)
    )
  )
)
;==================================================================================================
(defun c:ddedit (/ pstr)
(setq pstr "\n<Select a TEXT or ATTDEF object> ")
  (if c:ded nil (load"ded"))
  (c:ded pstr)
)
;==================================================================================================
(defun c:ed ( / ent tspt tspt1 tspt2); was (PSTR / ENT TSPT ....)
;;;  (if dimscl nil (load"dimscl"))
;;;  (dimscl)
  (vl-load-com)
  (while
    (SETQ tssel (NENTSELP "\n<Select a TEXT or ATTDEF object>: "))
    (SETQ tsent (CAR tssel))
    (SETQ tspt (CADR tssel))
    (setq scrnsz (getvar"screensize"))
    (IF (AND (EQ (GETVAR "TILEMODE") 0) (> (GETVAR "CVPORT") 1))
      (PROGN
        (setq vportss (ssget "X" (LIST (CONS 0 "VIEWPORT")(CONS 69 (GETVAR "CVPORT")))))
        (SETQ vpdat (ENTGET (SSNAME vportss 0)))
        (SETQ vp_scale (/ (CDR(ASSOC 45 vpdat))(CDR(ASSOC 41 vpdat))))
	(SETQ ms_vsize (GETVAR "VIEWSIZE"))
        (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-false)
;;;	(COMMAND ".pspace")
	(SETQ ps_vsize (GETVAR "VIEWSIZE"))
        (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-true)
;;;	(COMMAND ".mspace")
	(SETQ pbscl (MIN (/ ps_vsize (/ ms_vsize vp_scale)) 1.0))
      )
      (SETQ pbscl 1.0)
    )




    (setq pboxsz (*(/(GETVAR"PICKBOX")(CADR(GETVAR"SCREENSIZE")))(GETVAR"VIEWSIZE")pbscl))
     (setq dvwtwst (getvar "viewtwist"))
     (setq tspt1  (polar tspt
			 (- (* 1.25 pi) dvwtwst)
			 (* (sin (* 0.25 pi)) pboxsz 2.0)
		  ) ;_ end of polar
	   tspt1a (polar tspt1 (- 0 dvwtwst) (* 2.0 pboxsz))
	   tspt2  (polar tspt
			 (- (* 0.25 pi) dvwtwst)
			 (* (sin (* 0.25 pi)) pboxsz 2.0)
		  ) ;_ end of polar
	   tspt2a (polar tspt2 (- 0 dvwtwst pi) (* 2.0 pboxsz))
     ) ;_ end of setq
;;;    (PRINC "\nWE SHOULD HAVE DRAWN A PLINE HERE! \n")
;;;    (PRINC tspt1)
;;;    (PRINC "\t")
;;;    (PRINC tspt2)
;;;    (PRINC)
;;;    (IF (AND tspt1 tspt2)
;;;     (command ".PLINE"
;;;	      TSPT1
;;;	      (list (car TSPT2) (cadr TSPT1))
;;;	      TSPT2
;;;	      (list (car TSPT1) (cadr TSPT2))
;;;	      "C"
;;;     ) ;_ end of COMMAND
;;;   )
;;;    (princ "\n\n		screensize=	")
;;;    (PRINC (GETVAR"SCREENSIZE"))
;;;    (princ "\n\n		viewsize=	")
;;;    (PRINC (GETVAR"VIEWSIZE"))
;;;    (princ "\n\n		zoomfactor=	")
;;;    (PRINC (GETVAR"ZOOMFACTOR"))
;;;    (princ "\n\n		dvwtwst=	")
;;;    (PRINC dvwtwst)
;;;    (princ "\n\n		pickbox=	")
;;;    (PRINC (GETVAR"PICKBOX"))
;;;    (princ "\n\n		pboxsz=	")
;;;    (PRINC pboxsz)
;;;    (princ (strcat "\n\n		tspt1=	(POLAR tspt1 (-(* 1.25 PI) " (RTOS DVWTWST 2 4) ") (*(SIN(* 0.25 PI)) " (RTOS PBOXSZ 2 4) " 2.0))"))
;;;    (princ (strcat "\n\n		tspt1a=	(POLAR tspt (- 0 " (RTOS DVWTWST 2 4) ") (* 2.0 " (RTOS PBOXSZ 2 4) "))"))
;;;    (PRINC)
;;;    (COMMAND "PLINE" TSPT1 TSPT1A TSPT2 TSPT2A "C"); tests CP pick points for match w/ pickbox at mult. zoom MS/PS combos
    (setq tss (ssget "CP" (list tspt1 tspt1a tspt2 tspt2a tspt1)
                      '((-4 . "<OR")
                        (0 . "TEXT")
                        (0 . "MTEXT")
                        (0 . "ARCALIGNEDTEXT")
                        (0 . "ATTRIB")
                        (0 . "ATTDEF")
                        (0 . "DIMENSION")
                        (0 . "MULTILEADER")
                        (0 . "LEADER")
                        (-4 . "<AND")
                          (0 . "INSERT")
                          (66 . 1)
                        (-4 . "AND>")
                      (-4 . "OR>")))
    );setq
;;;    (setq ent (entsel pstr))
    (if tss
      (progn (IF (OR (EQ tsent (SSNAME tss 0))
                     (NOT (OR (EQ (CDR (ASSOC 0 (ENTGET tsent))) "TEXT")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "MTEXT")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "ARCALIGNEDTEXT")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "ATTRIB")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "ATTDEF")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "DIMENSION")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "MULTILEADER")
                              (EQ (CDR (ASSOC 0 (ENTGET tsent))) "LEADER")
                              (AND (EQ (CDR (ASSOC 0 (ENTGET tsent))) "INSERT")
                                   (EQ (CDR (ASSOC 66 (ENTGET tsent))) 1)
                                   (/= (CDR (ASSOC 70 (ENTGET tsent))) 4)
                              ) ;_ end of AND
                          ) ;_ end of OR
                     ) ;_ end of NOT
                 ) ;_ end of OR
               (SETQ ent (SSNAME tss 0))
               (SETQ ent tsent)
             ) ;_ end of IF
        (if (or
              (eq "TEXT" (cdr(assoc 0 (entget ent))))
              (and
                (eq "MTEXT" (cdr(assoc 0 (entget ent))))
                (eq (length tssel) 2)
              )
              (eq "ATTDEF" (cdr(assoc 0 (entget ent))))
              (eq "MULTILEADER" (cdr(assoc 0 (entget ent))))
            )
          (progn
            (prompt (strcat "\n" (cdr(assoc 0 (entget ent))) " selected "))
            (prompt "\n<Select a TEXT or ATTDEF object> ")
            (command ".DDEDIT" ent)
          );progn
          (IF (OR
                (EQ "INSERT" (CDR (ASSOC 0 (ENTGET ent))))
                (EQ "ATTRIB" (CDR (ASSOC 0 (ENTGET ent))))
              )
            (progn
              (prompt (strcat "\nBLOCK selected "))
              (prompt "\nSelect Block: ")
              (command ".DDATTE" ent)
            );progn
            (if (OR
                  (eq "DIMENSION" (cdr(assoc 0 (entget ent))))
                  (eq "LEADER" (cdr(assoc 0 (entget ent))))
                )
              (progn
                (command ".ddedit" ent)
;;;                (setq dimstr (ustr 0 "Enter new dimension text or <enter> for Associative. " "" nil))
;;;                (command ".dim" "new" dimstr (cdr(assoc -1 (entget ent)))"")
;;;                (command)
              );progn
              (IF
                  (and
                    (eq "MTEXT" (cdr(assoc 0 (entget ent))))
                    (eq (cdr(assoc 0(ENTGET(CDR(ASSOC 330(ENTGET ent)))))) "BLOCK_RECORD")
                  )
                (progn
                  (setq ent (car(last tssel)))
                  (command ".ddedit" ent)
                )
                (IF (eq "ARCALIGNEDTEXT" (cdr(assoc 0 (entget ent))))
                  (PROGN
                    (COMMAND ".arctext" ent)
                  )
                  (prompt (strcat "\n" (cdr(assoc 0 (entget ent))) " selected "))
                )
              )
            );if
          );if
        );if
        (command)
      );progn
      (princ "\nNo TEXT, ATTRIBUTE, BLOCK w/attribs, or DIMENSION selected. ")
    );if
  );while
  (command)
  (princ "\nFunction Cancelled. ")
  (princ)
);defun
